package com.wlhse.controller;

import com.wlhse.dto.getDto.BaseGetDto;
import com.wlhse.dto.inDto.MessageInDto;
import com.wlhse.service.MessageService;
import com.wlhse.util.GetCurrentUserIdUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController("MessageController")
@RequestMapping("/api/v3")
//事故
public class MessageController {
    @Resource
    private MessageService messageService;

    @Resource
    private GetCurrentUserIdUtil getCurrentUserIdUtil;

    @RequestMapping(value = "/message/{id}", method = RequestMethod.DELETE, produces = "application/json; charset=utf-8")
    public String deleteAccidentRecord(@PathVariable int id) {
        return messageService.deleteMessage(id);
    }

    @RequestMapping(value = "/message/{id}", method = RequestMethod.PUT, produces = "application/json; charset=utf-8")
    public String updateAccidentRecord(@PathVariable int id) {
        return messageService.updateMessageStatus(id);
    }

    //查by Id
    @RequestMapping(value = "/message", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String queryAccidentRecordsById(@ModelAttribute BaseGetDto baseGetDto,HttpServletRequest request) {
        return messageService.queryMessage(getCurrentUserIdUtil.getUserId(request), baseGetDto);
    }

    //分页+条件查
    @RequestMapping(value = "/message_count", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String queryAccidentRecordByCondition(HttpServletRequest request) {
        return messageService.queryMessageCount(getCurrentUserIdUtil.getUserId(request));
    }

    //一键已读
    @RequestMapping(value = "/message/all", method = RequestMethod.PUT, produces = "application/json; charset=utf-8")
    public String updateAllMessage(HttpServletRequest request) {
        return messageService.updateStatusByToUserId(getCurrentUserIdUtil.getUserId(request));
    }

    //根据状态查询message
    @RequestMapping(value = "/message/status", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String getByStatus(HttpServletRequest request, @ModelAttribute MessageInDto messageInDto ){
        return messageService.getByStatus(getCurrentUserIdUtil.getUserId(request),messageInDto);
    }

}
